import { Resolver, Query, Args, Mutation } from '@nestjs/graphql';
import { UserService } from './user.service';
import { CurrentUser } from '../common/decorators/currentUser';
import { User } from '../graphql';
import { UnauthorizedException, BadRequestException, UseGuards } from '@nestjs/common';
import { AuthService } from '../auth/auth.service';

@Resolver('User')
export class UserResolver {

  constructor(private readonly userService: UserService){}
              // private readonly authService: AuthService) {}

  @Query('currentUser')
  async currentUser(@CurrentUser() user: User) {
    console.log('currentUser')
    return user;
  }

  // @Mutation('login')
  // async login(@Args() args: { username: string, password: string }) {
  //   const result = await this.authService.validateUser(args.username, args.password);
  //   if (!result) {
  //     throw new UnauthorizedException();
  //   }
  //   return await this.authService.login(result);
  // }

  @Mutation('changeUserPassword')
  async changePassword(@Args() args: { username: string, password: string, confirmPassword: string }) {
    // const result = await this.authService.validateUser(args.username, args.password);
    // if (!result) {
    //   throw new BadRequestException();
    // }
    return await this.userService.changePassword(args.username, args.password);
  }
}
